package com.example.jqying.androiddemo.recyclerView.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;
import com.example.jqying.androiddemo.recyclerView.adapter.HorizontalAdapter;

public class HorizontalRecyclerViewActivity extends AppCompatActivity {

    private RecyclerView mRvHorizontal;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_horizentol_recycler_view);
        mRvHorizontal = (RecyclerView)findViewById(R.id.rc_horizontal);

        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(HorizontalRecyclerViewActivity.this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); //选择水平
        mRvHorizontal.setLayoutManager(linearLayoutManager);

        //添加分割线OK 渐变色
        //这里运用了系统自带的分割线装饰，可以简单的只传入分割线方向
        //或者自定义分割线样式，通过自定义Drawable
        //
        DividerItemDecoration divider = new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL);
        divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.custom_horizontol_divider));
        mRvHorizontal.addItemDecoration(divider);


        //设置布局适配器,决定Item的样式
        mRvHorizontal.setAdapter(new HorizontalAdapter(HorizontalRecyclerViewActivity.this, new HorizontalAdapter.OnitemClickListener() {
            @Override
            public void onClick(int pos) {
                Toast.makeText(HorizontalRecyclerViewActivity.this,"Clicked:"+pos,Toast.LENGTH_SHORT).show();
            }
        }));




    }
}
